﻿using System;

#region MIT License text
/*
Copyright (c) 2009 Mark van Straten - Q42 B.V.

Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
*/
#endregion

namespace Q42.Wheels.Api.Nabaztag
{
    /// <summary>
    /// Choreograpy for an Ear
    /// </summary>
    public class EarChoreographyPart : ChoreographyPart
    {
        /// <summary>
        /// The ears from your position when your looking at your bunny
        /// </summary>
        public enum Ears
        {
            /// <summary>
            /// Right ear when looking at bunny
            /// </summary>
            RightEar = 1,
            /// <summary>
            /// Left ear when looking at bunny
            /// </summary>
            LeftEar = 0
        }

        /// <summary>
        /// Direction in which the ear will turn
        /// </summary>
        public enum RotationDirection
        {
            /// <summary>
            /// high->front->low->back->high 
            /// </summary>
            ForwardDirection = 0,
            /// <summary>
            /// high->back->low->front->high
            /// </summary>
            BackwardDirection = 1
        }

        /// <summary>
        /// The ear this action plays
        /// </summary>
        private Ears ear;
        /// <summary>
        /// The ear this action plays
        /// </summary>
        public Ears Ear
        {
            get { return this.ear; }
            private set { this.ear = value; }
        }

        /// <summary>
        /// Angle the ear will be positioned at, in degrees
        /// </summary>
        private Int16 earAngle;
        /// <summary>
        /// Angle the ear will be positioned at, in degrees
        /// </summary>
        /// <remarks>0-180</remarks>
        protected Int16 EarAngle
        {
            get { return this.earAngle; }
            private set
            {
                if (value < 0 || value > 180)
                    throw new ArgumentOutOfRangeException("Angle must be between 0 and 180");
                this.earAngle = value;
            }
        }

        /// <summary>
        /// Direction this action will turn the designated ear
        /// </summary>
        private RotationDirection direction;
        /// <summary>
        /// Direction this action will turn the designated ear
        /// </summary>
        /// <example>
        /// ForwardDirection = high->front->low->back->high 
        /// BackwardDirection = high->back->low->front->high
        /// </example>
        protected RotationDirection Direction
        {
            get { return this.direction; }
            private set { this.direction = value; }
        }

        /// <summary>
        /// Create this Action
        /// </summary>
        /// <param name="oActionTime">can not be negative. Based on Total cheography tempo this time is sequenced.</param>
        /// <param name="oTheEar"></param>
        /// <param name="oEarAngle">0-180 (degrees)</param>
        /// <param name="oDirection"></param>
        /// <example>Choreograpy.Tempo = 10, ActionTime = 25, then this action will play 25/10 = 2,5 seconds after start of play.</example>
        public EarChoreographyPart(Int16 oActionTime, Ears oTheEar, Int16 oEarAngle, RotationDirection oDirection)
            : base(oActionTime)
        {
            Ear = oTheEar;
            EarAngle = oEarAngle;
            Direction = oDirection;
        }

        /// <summary>
        /// Return the choreograpy for the Nabaztag/tag API in URL form
        /// </summary>
        /// <returns></returns>
        public override String GetChoreoGraphy()
        {
            return String.Format("{0},motor,{1},{2},0,{3}", ActionTime, (Int16)Ear, EarAngle, (Int16)Direction);
        }
    }

}
